<template>
	<view class="pageBox">
		<view class="company flex-between">
			<input type="text" class="companyIpt" placeholder="请输入物流公司" v-model="logisticsName">
			
		</view>

		<view class="orderNumber flex-row">
			<view class="orderNumberTitle">
				物流单号：
			</view>
			<input type="text" class="orderNumberIpt" placeholder="请填写单号" v-model="postNo">
		</view>

	<!-- 	<view class="upload">
			<view class="uploadTitle">
				上传凭证
			</view>
			<view class="uploadItem">
				<uni-file-picker class="picker" fileMediatype="image" mode="grid" @select="select"
					@delete="pickerDelete" :image-styles="imageStyles">
					<image class="uploadBg" src="http://www.bobei.shop/static/my/uploadBg.png"></image>
				</uni-file-picker>
			</view>
		</view> -->

		<button class="btn" :plain="true" @click="onBtn">提交</button>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: "", // 订单id
				refundId: "", // 退款id
				orderGoodsId: "", // 商品订单ID
				postNo: "", // 物流编码
				logisticsName: "", // 物流公司
				info: {
					"orderNo": "",
					"addressId": {
						"name": "",
						"mobile": "",
						"address": ""
					},
					"status": 0,
					"num": 1,
					"orderGoods": [{
						"id": 3779,
						"shopId": 0,
						"orderId": 3705,
						"goodsId": 42427,
						"price": "0.00",
						"status": 0,
						"refundId": 0,
						"refundNum": 0,
						"refundMoney": "0.00",
						"deletedAt": null,
						"createdAt": "2022-11-18 11:16:54",
						"updatedAt": "2022-11-18 11:16:54",
						"specs": "",
						"specTitle": "",
						"credits": 0,
						"num": 1,
						"title": "",
						"thumb": "",
						"genre": 0,
						"marketprice": "0.00",
						"score": 0,
						"commentType": 0,
						"refund": null
					}]
				},
				imageValue: [],
				imageStyles: {
					width: 100,
					height: 100,
					border: {
						color: "transparent",
						width: 0,
						style: 'dashed',
						radius: '0rpx'
					}
				},
			}
		},
		onLoad(option) {
			this.id = option.id;
			this.getINfo();
		},
		methods: {
			getINfo() {
				this.$post({
					url: '/portal/Shop',
					module: 'Order',
					interface: '1001',
					data: {
						id: Number(this.id)
					}
				}).then(res => {
					this.info = res;
					res.orderGoods.forEach((item) => {
						if (item.refund) {
							this.refundId = item.refund.id;
							this.orderGoodsId = item.refund.orderId;
						}
					})
				})
			},
			// 获取上传状态
			select(e) {
				// // console.log('选择文件：', e);
				this.$upload({
					data: {
						filePath: e.tempFilePaths[0]
					}
				}).then((res) => {
					let obj = {
						payImg: res.file,
						tempFilePath: e.tempFilePaths[0],
					}
					this.imageValue.push(obj);
					// console.log("imageValue:", this.imageValue);
				}).catch((error) => {
					// console.log("上传error：", res);
				})
			},
			// 文件从列表移除时触发
			pickerDelete(e) {
				// // console.log('文件从列表移除时触发：', e);
				this.imageValue.forEach((item, index) => {
					if (item.tempFilePath === e.tempFilePath) {
						this.imageValue.splice(index, 1);
					}
				})
			},
			onBtn() {
				if (!this.logisticsName) {
					uni.showToast({
						title: '请输入物流公司',
						duration: 1500,
						icon: 'none',
					});
					return;
				}
				if (!this.postNo) {
					uni.showToast({
						title: '请填写物流编号',
						duration: 1500,
						icon: 'none',
					});
					return;
				}
				// if (!this.imageValue.length) {
				// 	uni.showToast({
				// 		title: '请上传凭证',
				// 		duration: 1500,
				// 		icon: 'none',
				// 	});
				// 	return;
				// }
				// let payImg = [];
				// this.imageValue.forEach((item) => {
				//   payImg.push(item.payImg)
				// })
				
				this.$post({
					url: '/portal/Shop',
					module: 'Order',
					interface: '1010',
					data: {
						id: Number(this.id),
						goodsId: Number(this.info.goodsId),
						refundId: this.refundId,
						orderGoodsId: this.orderGoodsId,
						postNo: this.postNo,
						post: this.logisticsName,
					}
				}).then(res => {
					uni.showToast({
						title: '提交成功',
						duration: 1500,
						icon: 'none',
					});
					setTimeout(() => {
						this.goBack();
					}, 1000)
				})
			},
			goBack() {
				const pages = getCurrentPages()
				if (pages.length === 1) {
					if (typeof params === 'number') {
						history.go(-params)
					} else {
						history.back()
					}
				} else {
					uni.navigateBack({
						delta: 1
					});
				}
			},
		},
	}
</script>

<style scoped lang="scss">
	.pageBox {
		width: 100%;
		min-height: calc(100vh - var(--window-top));
		background-color: #f9f9f9;
		padding: 32rpx;

		.company {
			background: #ffffff;
			border-radius: 16rpx;
			padding: 32rpx;
			margin-bottom: 32rpx;

			.companyIpt {
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #666666;
			}
		}

		.orderNumber {
			background: #ffffff;
			border-radius: 16rpx;
			padding: 32rpx;
			margin-bottom: 32rpx;

			.orderNumberTitle {
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #666666;
			}

			.orderNumberIpt {
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #666666;
			}
		}

		.upload {
			width: 100%;
			margin-top: 32rpx;
			border-radius: 16rpx;
			background: #ffffff;
			padding: 32rpx 0;

			.uploadTitle {
				font-size: 28rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #999999;
				padding-left: 32rpx;
				margin-bottom: 42rpx;
			}

			.uploadItem {
				padding: 0 16rpx;


				/deep/.uni-file-picker {
					background: #ffffff;
					border-radius: 16rpx;
				}

				/deep/.file-picker__box {
					margin: 0 13rpx;
				}

				/deep/.uni-file-picker__container {
					background: #ffffff;
				}

				/deep/.file-picker__box {
					background: #ffffff;
				}

				.uploadBg {
					width: 210rpx;
					height: 210rpx;
				}
			}
		}

		.btn {
			font-size: 36rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			color: #ffffff;
			width: 606rpx;
			height: 104rpx;
			background: #F2615F;
			border-radius: 52rpx;
			border: none;
			margin: 168rpx auto 0;
		}

	}
</style>
